package com.lian.anlimall.order.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lian.anlimall.order.entity.OrderEntity;
import com.lian.anlimall.order.interceptor.LoginUserInterceptor;
import com.lian.common.utils.PageUtils;
import com.lian.common.utils.Query;
import com.lian.anlimall.order.dao.OrderItemDao;
import com.lian.anlimall.order.entity.OrderItemEntity;
import com.lian.anlimall.order.entity.OrderReturnReasonEntity;
import com.lian.anlimall.order.service.OrderItemService;
import com.lian.common.vo.MemberResponseVo;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.core.MessageProperties;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;


@Service("orderItemService")
public class OrderItemServiceImpl extends ServiceImpl<OrderItemDao, OrderItemEntity> implements OrderItemService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<OrderItemEntity> page = this.page(
                new Query<OrderItemEntity>().getPage(params),
                new QueryWrapper<OrderItemEntity>()
        );

        return new PageUtils(page);
    }

    @Override
    public PageUtils queryPageWithItem(Map<String, Object> params, String orderSn, Long skuId) {

//        MemberResponseVo memberResponseVo = LoginUserInterceptor.loginUser.get();

        IPage<OrderItemEntity> page = this.page(
                new Query<OrderItemEntity>().getPage(params),
                new QueryWrapper<OrderItemEntity>()
                        .eq("order_sn", orderSn).eq("sku_id",skuId)
        );

//        //遍历所有订单集合
//        List<OrderEntity> orderEntityList = page.getRecords().stream().map(order -> {
//            //根据订单号查询订单项里的数据
//            List<OrderItemEntity> orderItemEntities = orderItemService.list(new QueryWrapper<OrderItemEntity>()
//                    ;
//            order.setOrderItemEntityList(orderItemEntities);
//            return order;
//        }).collect(Collectors.toList());
//
//        page.setRecords(orderEntityList);

        return new PageUtils(page);
    }



    /**
     * queues：声明需要监听的队列
     * channel：当前传输数据的通道
     */
    //@RabbitListener(queues = {"hello-java-queue"})
    public void revieveMessage(Message message,
                               OrderReturnReasonEntity content) {
        //拿到主体内容
        byte[] body = message.getBody();
        //拿到的消息头属性信息
        MessageProperties messageProperties = message.getMessageProperties();
        System.out.println("接受到的消息...内容" + message + "===内容：" + content);

    }

}